<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打印菱形，三角形</title>
    <script>
        //打印菱形
        var line = parseInt(prompt('请输入行数'))
        for (var i = 0; i < line - 1; i++) {
            for (var j = 0; j < line - i; j++) {
                document.write('&nbsp;')
            }
            for (var k = 0; k < 2 * i + 1; k++) {
                document.write('*')
            }
            document.write('<br>')
        }
        for (var i = line - 1; i >= 0; i--) {
            for (var j = 0; j < line - i; j++) {
                document.write('&nbsp;')
            }
            for (var k = 0; k < 2 * i + 1; k++) {
                document.write('*')
            }
            document.write('<br>')
        }

        //打印三角形
        var star = '*'
        for (var i = 0; i < 4; i++) {
            document.write(star + '<br>')
            star += '*'
        }
    </script>
</head>

<body>

</body>

</html>